# Title: Log Rotate
# 
# Description: Simple script for automatically deleting logs older then a certain time.
# 
# Created by: Eric (eric[at]fizi.ca)
# Version: 1.0
# Created date: Sept. 22nd, 2008

$logsToRotate = "" #Full path to the logs that we are going to delete
$rotateLog = "" #Full path to a location you'd like the log from this script to be stored in
$compareDate = (Get-Date).AddDays(-14) #Number of days to keep logs for
$currentDate = Get-Date #The current date for the log file this script creates

echo "Files deleted on -- $currentDate" >> $rotateLog #Appends this header to the bottom of this scripts log file

Get-ChildItem $logsToRotate\*.log | Where-Object {$_.LastWriteTime -lt $compareDate} >> $rotateLog #Appends a list of the files to be deleted to the bottom of this scripts log file
Get-ChildItem $logsToRotate\*.log | Where-Object {$_.LastWriteTime -lt $compareDate} | Remove-Item #Deletes files older then the specified amount of time